<template>
  <div class="center-setting">
    <Breadcrumb :options="crumbOptions"></Breadcrumb>
    <div class="policyDetail">
      <div class="policyDetail-content" style="width: 100%">
        <div class="title">{{ result.title }}</div>
        <div class="summary">
          <span>发布于：{{ result.pulishDate }}</span>
          <span>来源：{{ result.source }}</span>
        </div>
        <div class="content">
          <div v-html="result.content"></div>
          <div class="mt20" v-if="result.files && result.files[0]">
            附件下载：
            <div v-for="item in result.files" :key="item.id" class="down">
              <div>
                <span class="name">{{ item.fileName }}</span>
                <a-icon class="icon" type="download" @click="downClick(item)" />
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Breadcrumb from '@/components/common/Breadcrumb'
import { getCurrentCrumb } from '@/utils/crumb.js'
import { getDataStatisticsDetail } from '@/api/dataStatistics'

export default {
  components: {
    Breadcrumb
  },
  data() {
    return {
      crumbOptions: [],
      result: []
    }
  },
  mounted() {
    this.initData()
  },
  methods: {
    async initData() {
      const { id } = this.$route.query
      const { data } = await getDataStatisticsDetail(id)
      this.result = data
    },
    settingCrumb() {
      const { path } = this.$route
      const crumbOptions = getCurrentCrumb(path)
      this.crumbOptions = crumbOptions
    },
    async downClick(item) {
      const a = document.createElement('a')
      a.href = item.filePath
      a.download = item.fileName
      a.click()
    }
  },
  created() {
    this.settingCrumb()
  },
}
</script>